﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;

public class OperatorFolk : MonoBehaviour
{
    public GameObject showBall;
    public GameObject flok;
    public GameObject camera;
    public GameObject opBall;
    public GameObject cameraPos;
    private GameObject player;
    private bool inArea = false;
    private bool startFlok = false;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(inArea&&Input.GetKeyUp(KeyCode.E))
        {
            startFlok = !startFlok;
        }
        if (inArea)
        {
            if (startFlok)
            {
                player.GetComponent<ThirdPersonUserControl>().enabled = false;
                flok.GetComponent<FolkLoader>().enabled = true;
                opBall.GetComponent<CarmeraBind>().isGetCamera = false;
                camera.transform.position = cameraPos.transform.position;
                camera.transform.rotation = cameraPos.transform.rotation;
            }
            else
            {
                player.GetComponent<ThirdPersonUserControl>().enabled = true;
                flok.GetComponent<FolkLoader>().enabled = false;
                opBall.GetComponent<CarmeraBind>().isGetCamera = true;
            }
        }

    }
    private void OnTriggerEnter(Collider other)
    {
        if(other.tag.Equals("Player"))
        {
            inArea = true;
            player = other.gameObject;
            showBall.GetComponent<BindShowText>().setShowText("按“E”使用或退出叉车");
            showBall.GetComponent<BindShowText>().showShowText();
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.tag.Equals("Player"))
        {
            inArea = false;
            player = null;
            showBall.GetComponent<BindShowText>().setShowText("");
            showBall.GetComponent<BindShowText>().showShowText();
        }
    }
}
